/**
 * @Title: CarController.java
 * @Package com.qding.park.api.web.service.controller
 * @Description: TODO
 * Copyright: Copyright (c) 2011 
 * Company:千丁互联
 * 
 * @author Comsys-Administrator
 * @date 2016年8月16日 下午2:46:52
 * @version V1.0
 */

package com.qding.park.manager.rest.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qding.park.common.core.exceptions.ExceptionMessage;
import com.qding.park.common.core.exceptions.system.SystemUnKnown;
import com.qding.park.manager.common.pojo.ParkDataResult;
import com.qding.park.manager.common.rest.domain.AnswerMsg;
import com.qding.park.manager.common.rest.domain.AnswerMsgFactoryImpl;
import com.qding.park.manager.common.rest.enums.ResponseCodeEnum;
import com.qding.park.manager.facade.core.service.DemoFacade;
import com.qding.park.manager.facade.core.service.common.ParkCommonFacade;

/**
 * @ClassName: CarController
 * @Description: 规则 Controller
 * @author Comsys-Administrator
 * @date 2016年8月16日 下午2:46:52
 *
 */
@RestController
public class RuleController extends WebBaseController {

	private static final Log _log = LogFactory.getLog(RuleController.class);
	
	private static final String parkRulePage = "parkRule";
	
	@Autowired
	private ParkCommonFacade  ruleFacade;
	
	@Autowired
	private  DemoFacade demoFacade;
	
	/**
	 * @Description (查询车场规则)
	 * @param parkId
	 * @return 这是一个页面
	 */
	@RequestMapping("/parking/calRules")
	public AnswerMsg rule(String parkId) {
		try {
			_log.info("parkId:" + parkId);
			int parkIdInt=Integer.valueOf(parkId);
			ParkDataResult parkDataResult =null;
			if(this.isDemoRequestByparkid(parkId)){
				//演示请求
				parkDataResult=demoFacade.getRuleByParkId(parkIdInt);
			}else{
				parkDataResult = ruleFacade.getRuleByParkId(parkIdInt);
			}
			
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(parkDataResult.getData());
			return answerMsg;
		} catch (Exception e) {
			SystemUnKnown ex = new SystemUnKnown(e,
					ExceptionMessage.createExceptionMessage(SystemUnKnown.default_Name, "未知Exception",
							"parkId=" + parkId) );
			exceptionHandle.handle(ex);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.SYSTEM_ERROR);
			return answerMsg;
		}
	}
	
	
}
